#include <auto/autoclose.h>

AutoClose::AutoClose(QIODevice& device, QIODevice::OpenMode flags) :
    mDevice(device),
    mShouldClose(false)
{
    if (!mDevice.isOpen() && mDevice.open(flags)) {
        mShouldClose = true;
    }
}

AutoClose::~AutoClose() {
    if (mShouldClose) {
        mDevice.close();
    }
}

bool AutoClose::isOpen() {
    return mDevice.isOpen();
}

